package com.mh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mh.dao.StudentInfoDao;
import com.mh.pojo.StudentInfo;
import com.mh.service.StudentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * Date:2023/4/13
 * author:zmh
 * description:学生信息业务层实现类
 **/

@Service
public class StudentInfoServiceImpl extends ServiceImpl<StudentInfoDao, StudentInfo> implements StudentInfoService {

    @Autowired
    private StudentInfoDao studentInfoDao;

    /**
     * (登录验证)学生信息表-检查输入信息是否匹配
     * @param userName 姓名
     * @param password 联系方式
     * @return 验证结果，true为验证成功，false为验证失败
     */
    @Override
    public String checkLoginByStudent(String userName, String password) {
        // 先将传入的密码进行md5加密后再进行进行验证
        String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());
        // 条件构造器-根据传入姓名查询数据库中是否存在此用户
        LambdaQueryWrapper<StudentInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StudentInfo::getName,userName);
        StudentInfo studentInfo = studentInfoDao.selectOne(queryWrapper);
        if (studentInfo == null){
            return "登录失败！输入的学生未录入";
        } else if (!studentInfo.getPassword().equals(md5Password)) {
            return "登录失败！输入的账号密码不匹配";
        }
        return "登录成功!";
    }

}
